// ==================================================================================
// Shared Genomics Project MPI Codebase
// Version 1.0 30/04/2010
//
// (c) 2010 University of Manchester all rights reserved
//
// This file is distributed under the GNU General Public License, Version 2.  
// Please see the file COPYING.txt for more details
// ==================================================================================

/*!
\file
\brief Implementation of Test statistic/P-value Array Pair
*/

#include <stdio.h>
#include <stdlib.h>

#include "ppair.h"

struct ppair* ppair_create_array(int n) {
	struct ppair* values = NULL;

	if (n > 0) {
		values = (struct ppair*) malloc(sizeof(struct ppair) * n);
		if (values != NULL) {
			int i;
			for (i = 0; i < n; i++) {
				values[i].l = 0;
				values[i].p = 1.0;
			}
		}
	}

	return values;
}

// QSORT comparator function.
int ppair_cmp(const void* p1, const void* p2) {
	const struct ppair *a = (const struct ppair*) p1;
	const struct ppair *b = (const struct ppair*) p2;

	if (a == NULL || b == NULL) return 0;

	if (a->p < b->p) return -1;
	else if (a->p > b->p) return 1;
	else return  0;
}

void ppair_echo(struct ppair* pp) {
	if (pp != NULL) fprintf(stdout, "l=%i p=%f\n", pp->l, pp->p);
}